package com.ustropo.financas.conta;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.ustropo.financas.FinancasSQLHelper;
import com.ustropo.financas.R;

/**
 * 
 * @author Fernando C. de Souza
 * @version 1.0
 * @since 25/10/2013
 */
public class ContaActivity extends Fragment {

	/* variáveis */
	private ContaDAO dataSource;
	
	
	/*
	 * (non-Javadoc)
	 * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View view = inflater.inflate(R.layout.activity_conta,
				container, false);
		
		// cria a conexao com banco de dados
		FinancasSQLHelper helper = new FinancasSQLHelper(getActivity());
		dataSource = new ContaDAO(helper);
		List<IConta> contas = dataSource.getAllContas();
		
		// Pega a lista
		ContaAdapter adapter = new ContaAdapter(getActivity(), contas);
		ListView lv = (ListView) view.findViewById(R.id.conta_listview);
		lv.setAdapter(adapter);
		
		return view;
	}

	/*
	 * (non-Javadoc)
	 * @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
	 */
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}
}
